home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / WIN_SND / PLAYWV.ZIP;1 / PLAYWAVE.CPP next >
Encoding:
C/C++ Source or Header  |  1993-05-06  |  4.3 KB  |  164 lines

  1.  
  2. //  playwave.cpp
  3. //
  4. //  WAVE File Player
  5. //
  6. //  by Chris Peterson (Compuserve ID: 76550,3670)
  7. //
  8. //  Written on May 6, 1993
  9. //
  10. //  Note:  Set Tab Stops to 4
  11.  
  12. #include <windows.h>
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <commdlg.h>
  16. #include <mmsystem.h>
  17.  
  18.  
  19. #define        ID_PLAY        101        //  Play WAVE File Menu Choice
  20. #define        ID_REPLAY   102        //  Replay WAVE File Menu Choice
  21. #define        ID_EXIT        103        //  Exit This Program Menu Choice
  22. #define        ID_ABOUT    104        //  About This Program Menu Choice
  23.  
  24. static OPENFILENAME ofn;        //  Open File Dialog Structure
  25.  
  26. static char WaveFileName[100],    //  WAVE Input File Pathname
  27.             WaveTitleName[20];    //  WAVE Input File Basename
  28.  
  29. int GetFileName(HWND);            //  Get WAVE Filename to Play
  30.  
  31.  
  32. void PlayWave(char *);            //  Play The File
  33.  
  34. long FAR PASCAL _export WndProc(HWND, UINT, UINT, LONG);    //  Main Message Processer
  35.  
  36. int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpszCmdParam, int nCmdShow)
  37. {
  38.     static char szAppName[] = "WAVE File Player";
  39.     HWND        hwnd;
  40.     MSG         msg;
  41.     WNDCLASS    wndclass;
  42.     DWORD         WStyle = WS_POPUPWINDOW | WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX;
  43.  
  44.     if (hPrevInstance == 0)
  45.     {
  46.         wndclass.style         = CS_HREDRAW | CS_VREDRAW;
  47.         wndclass.lpfnWndProc   = WndProc;
  48.         wndclass.cbClsExtra    = 0;
  49.         wndclass.cbWndExtra    = 0;
  50.         wndclass.hInstance     = hInstance;
  51.         wndclass.hIcon         = LoadIcon (hInstance, "WAVE");
  52.         wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW);
  53.         wndclass.hbrBackground = GetStockObject (WHITE_BRUSH);
  54.         wndclass.lpszMenuName  = "WAVEMENU";
  55.         wndclass.lpszClassName = szAppName;
  56.         RegisterClass(&wndclass);
  57.     }
  58.  
  59.     hwnd = CreateWindow(szAppName,          //  Window Class Name
  60.             "WAVE File Player",             //  Window Caption
  61.             WStyle,                         //  Window Style
  62.             150,                            //  Initial x Position
  63.             100,                            //  Initial y Position
  64.             300,                            //  Initial x Size
  65.             250,                            //  Initial y Size
  66.             NULL,                           //  Parent Window Handle
  67.             NULL,                           //  Window Menu Handle
  68.             hInstance,                      //  Program Instance Handle
  69.             NULL);                            //  Creation Parameters
  70.  
  71.     ShowWindow(hwnd, nCmdShow);
  72.     UpdateWindow(hwnd);
  73.  
  74.     while (GetMessage(&msg, NULL, 0, 0) != 0)
  75.     {
  76.         TranslateMessage (&msg);
  77.         DispatchMessage (&msg);
  78.     }
  79.     return(msg.wParam);
  80. }
  81.  
  82.  
  83. long FAR PASCAL _export WndProc(HWND hwnd, UINT message, UINT wParam, LONG lParam)
  84. {
  85.     HDC         hdc;
  86.     PAINTSTRUCT ps;
  87.     static int    gf = 0;
  88.  
  89.     switch (message)
  90.     {
  91.         case WM_PAINT:
  92.             BeginPaint(hwnd, &ps);
  93.             EndPaint(hwnd, &ps);
  94.             return(0);
  95.  
  96.         case WM_COMMAND:
  97.             if (wParam == ID_PLAY)
  98.             {
  99.                 if ((gf = GetFileName(hwnd)) != 0)
  100.                 {
  101.                     PlayWave(WaveFileName);
  102.                 }
  103.             }
  104.             else if (wParam == ID_REPLAY && gf != 0)
  105.             {
  106.                 PlayWave(WaveFileName);
  107.             }
  108.             else if (wParam == ID_EXIT)
  109.             {
  110.                 SendMessage(hwnd,WM_DESTROY,NULL,NULL);
  111.             }
  112.             else if (wParam == ID_ABOUT)
  113.             {
  114.                 MessageBox(hwnd,"by Chris Peterson","WAVE File Player",MB_OK);
  115.             }
  116.             return(0);
  117.  
  118.         case WM_DESTROY:
  119.             PostQuitMessage(0);
  120.             return(0);
  121.  
  122.     }
  123.     return(DefWindowProc(hwnd, message, wParam, lParam));
  124. }
  125.  
  126.  
  127. //  Input WAVE Filename to Play
  128.  
  129. int GetFileName(HWND hwnd)
  130. {
  131.     static char *szFilter[] = { "WAVE Files", "*.wav", "", "" };
  132.  
  133.     ofn.lStructSize       = sizeof(OPENFILENAME);
  134.     ofn.hwndOwner         = hwnd;
  135.     ofn.hInstance         = NULL;
  136.     ofn.lpstrFilter       = szFilter[0];
  137.     ofn.lpstrCustomFilter = NULL;
  138.     ofn.nMaxCustFilter    = 0;
  139.     ofn.nFilterIndex      = 0;
  140.     ofn.lpstrFile         = WaveFileName;
  141.     ofn.nMaxFile          = 100;
  142.     ofn.lpstrFileTitle    = WaveTitleName;
  143.     ofn.nMaxFileTitle     = 20;
  144.     ofn.lpstrInitialDir   = NULL;
  145.     ofn.lpstrTitle        = "Select a WAVE File";
  146.     ofn.Flags             = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST;
  147.     ofn.nFileOffset       = 0;
  148.     ofn.nFileExtension    = 0;
  149.     ofn.lpstrDefExt       = "wav";
  150.     ofn.lCustData         = 0L;
  151.     ofn.lpfnHook          = NULL;
  152.     ofn.lpTemplateName    = NULL;
  153.  
  154.     return(GetOpenFileName(&ofn));
  155. }
  156.  
  157.  
  158. //  Play The WAVE File
  159.  
  160. void PlayWave(char *Filename)
  161. {
  162.     sndPlaySound(Filename,SND_ASYNC);
  163. }
  164.